// JavaScript Document
((function(a){
	//插件本体
	var kplug = function(opts){
		this.multiple = (opts.multiple!=undefined)?opts.multiple:false;
		this.pgressnum = (opts.pgressnum!=undefined)?opts.pgressnum:1;
		this.code = (opts.code!=undefined)?opts.code:100;//总量大小
		this.npgressnum = 1;//需要上传的文件进程数量
		this.ncode = 0,//当前占用的百分比
		this.elecode = null;//code的元素
		this.elepgressnum = null;//进程数量的元素
		this.elencode = null;//code的元素
		this.elenpgressnum = null;//进程数量的元素
		this.processbar = null;
		this.card = null;//当前进程的卡片
		this.isRunning = true;
		//手动创建
		this.create = function(){
			this.remove();
			this.isRunning = true;
			var conts = a.kuoqiJs('<div style="font-size: small;padding-left: 1em;color: #666;"></div>');
			this.elepgressnum = a.kuoqiJs('<span>'+this.pgressnum+'</span>');
			this.elecode = a.kuoqiJs('<span>'+this.code+'</span>');
			this.elenpgressnum = a.kuoqiJs('<span>'+this.npgressnum+'</span>');
			this.elencode = a.kuoqiJs('<span>'+this.ncode+'</span>');
			conts.append(this.elencode);
			conts.append('<span>/</span>');
			conts.append(this.elecode);
			//排除文本还有个进度条的信息
			var process = a.kuoqiJs('<div style="width: 12rem;;height: 0.4em;border: 1px solid #666;position:relative;"></div>');
			this.processbar = a.kuoqiJs('<div style="position: absolute;height: 100%;width: 10%;background-color: #666;max-width:99%;left: -1px;"></div>');
			process.append(this.processbar);
			var content = a.kuoqiJs('<div data-api-id="process" style="display: flex;text-align: center;align-items: center;padding: 15px;"></div>');
			content.append(process);
			content.append(conts);
			this.card = a.kuoqiJs.card({
				format:['body'],
				content:content,	
			});
			
		};
		//手动展示
		this.show = function(){};
		//手动隐藏
		this.hide = function(){};
		//手动清除占用
		this.remove = function(){
			if(!this.card){ return;}
			this.isRunning = false;
			a.kuoqiJs('div[data-api-id="process"]').remove();
			this.card.remove();
			
		};
		//同步内容
		this.sync = function(){
			if(!this.isRunning){return;}
			this.ncode = parseFloat(this.ncode);
			this.code = parseFloat(this.code);
			if(this.ncode>=this.code){ 
				this.ncode = this.code - 1;
				//触发停止
				this.isRunning = false;
			}
			this.elencode.html(this.ncode);	
			this.elecode.html(this.code);	
			this.processbar.css('width',(this.ncode / this.code ) * 100 + "%");
		};
		//单个进度显示的内容配置，第一个参数为当前的百分比，第二个 参数为多文件时候当前的文件为多少个
		this.progress = function(ncode,npgressnum){
			this.npgressnum = (npgressnum==undefined)?1:npgressnum;
			this.ncode = ncode;
			this.sync();
		};
		this.create();
	};
	a.kuoqiJs.plugIn.register('progress',kplug);
})(this))